package com.ms.p2p.utils;



import com.ms.p2p.entity.loan.Loan;

import java.math.BigDecimal;
import java.math.RoundingMode;

public class AmountUtil {

    public static void cacueInterest(Loan borrow){
        BigDecimal interest = new BigDecimal(0);
        // 天标（只有一次性还本付息）
        if (borrow.getIs_day() == 1) {
            interest = borrow.getAccount().multiply(borrow.getApr().divide(new BigDecimal(36000), 10, 4))
                    .multiply(new BigDecimal(borrow.getTime_limit())).setScale(2, RoundingMode.HALF_EVEN);
            borrow.setRepayment_account(borrow.getAccount().add(interest));
        } else {
            // 月标
            if (borrow.getPay_style().equals("1")) {
                borrow.setRepayment_account(AverageCapitalPlusInterestUtils.getPrincipalInterestCount(borrow.getAccount().doubleValue(),borrow.getApr().doubleValue()/100,borrow.getTime_limit()));
            } else {
                interest = borrow.getAccount().multiply(borrow.getApr().divide(new BigDecimal(1200), 10, 4))
                        .multiply(new BigDecimal(borrow.getTime_limit())).setScale(2, RoundingMode.HALF_EVEN);
                borrow.setRepayment_account(borrow.getAccount().add(interest));
            }
        }

    }
}
